from war_utils import *

game_is_running = True
rounds = 1

magic1 = {
    "name": "zxy",
    "life": 100,
    "type": "火焰",
    "hit_rate": 0.8,
    "attack": 40,
}


soldier1 = {
    "name": "hxb",
    "life": 200,
    "step": 2,
    "type": "防御",
    "attack": 200,
    "distance": 10,
    "state": 1  # 1表示前进，0表示防守
}

print("游戏开始")
while game_is_running:
    print("---------第%i回合---------" % rounds)
    if magic1["life"] <= 0 or soldier1["life"] <= 0:
        game_is_running = False
        break
    print("法师的回合:")
    if magic1["life"] > 0 and probability_judge(magic1["hit_rate"]):
        if soldier1["state"] == 1:
            print(">>>>%s使用了%s系法术，击中了%s，造成了%i点伤害" % (magic1["name"], magic1["type"], soldier1["name"], magic1["attack"]))
            soldier1["life"] -= magic1["attack"]
        else:
            print(">>>>%s使用了%s系法术，击中了防御姿态的%s，效果一般，造成了%i点伤害" % (magic1["name"], magic1["type"], soldier1["name"], 0.2*magic1["attack"]))
            soldier1["life"] -= 0.2*magic1["attack"]
    else:
        print(">>>>%s使用了%s系法术，法术丢失了！" % (magic1["name"], magic1["type"]))

    print("\n战士的回合")
    print("您的剩余血量：%i" % soldier1["life"])
    if soldier1["distance"] <= 1:
        print(">>>>战士%s发动了致命一击！！！造成了%i点巨量伤害" % (soldier1["name"], soldier1["attack"]))
        magic1["life"] = 0
    else:
        soldier1["distance"] -= soldier1["step"]
        print(">>>>战士%s向前冲锋，距离法师还有%i个单位" % (soldier1["name"], soldier1["distance"]))
    soldier1["state"] = int(input("请输入您下回合需要执行的操作，1表示前进，0表示防御:"))
    print("-------------此回合结束------------\n")

    rounds += 1


if magic1["life"] > 0:
    print("法师胜！")
else:
    print("战士胜！")

